home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / µSim 1.1 / FabLibsƒ / UtilsCommon.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-25  |  10.3 KB  |  383 lines  |  [TEXT/CWIE]

  1. #ifndef __HFABUTILSCOMMON__
  2. #define __HFABUTILSCOMMON__
  3.  
  4.  
  5. #ifndef __FSPCOMPAT__
  6. #include <FSpCompat.h>
  7. #endif
  8.  
  9. #if defined(FabSystem7orlater)
  10.  
  11. #define    FabStandardGetFile(a,b,c,d)    StandardGetFile(a,b,c,d)
  12. #define    FabStandardPutFile(a,b,c)    StandardPutFile(a,b,c)
  13.  
  14. #else
  15.  
  16. #include    "Utils6.h"
  17.  
  18. #endif
  19.  
  20. enum
  21. {
  22. kCacheMask   = 0x0010,
  23. kNoCacheMask = 0x0020
  24. };
  25.  
  26.  
  27. /*    kScrollbarAdjust and kScrollbarWidth are used in calculating
  28.     values for control positioning and sizing. */
  29. enum {
  30. kScrollbarAdjust = 15,
  31. kScrollbarWidth
  32. };
  33.  
  34. /* Menu list resource IDs */
  35. enum menures {
  36. kRes_Menu_Apple = 128,
  37. kRes_Menu_File,
  38. kRes_Menu_Edit
  39. };
  40.  
  41. enum edititems {
  42. kMItem_Undo = 1,
  43. kMItem_Cut = 3,
  44. kMItem_Copy,
  45. kMItem_Paste,
  46. kMItem_Clear,
  47. kMItem_Select_All
  48. };
  49.  
  50. enum {
  51. kUndoKey = 0x7A10,
  52. kCutKey = 0x7810,
  53. kCopyKey = 0x6310,
  54. kPasteKey = 0x7610,
  55. kHelpKey = 0x7205,
  56. kFwdDel = 0x757F,
  57. kHomeKey = 0x7301,
  58. kEndKey = 0x7704,
  59. kPgUpKey = 0x740B,
  60. kPgDnKey = 0x790C,
  61. kClearKey = 0x471B,
  62. kEscapeKey = 0x351B,
  63. kEnterKey = 0x4C03
  64. };
  65.  
  66. /* for KeyState */
  67. enum {
  68. kCommandKeyCode = 55,
  69. kShiftKeyCode,
  70. kCapsLockKeyCode,
  71. kOptionKeyCode,
  72. kControlKeyCode
  73. };
  74.  
  75. enum {
  76. kWantRestart = false,
  77. kWantShutdown = true
  78. };
  79.  
  80. enum {
  81. kCreat = 'FABR',
  82. kAEAlert = 'ALRT'
  83. };
  84.  
  85. enum {
  86. kDITLItem_AboutPICT = 3,
  87. kItemUserName = 3,
  88. kItemCompany,
  89. kItemAddress,
  90. kItemCity,
  91. kItemState,
  92. kItemZIP,
  93. kItemCountry,
  94. kItemE_mail,
  95. kItemPhone,
  96. kItemFAX,
  97. kItemQuantity,
  98. kItemCopyFrom,
  99. kItemComments,
  100. kItemTotals = 27
  101. };
  102.  
  103. enum {
  104. kFSMacintosh = 0,
  105. kFSProDOS = 0x100,
  106. kFSMSDOS = 0x4953
  107. };
  108.  
  109. enum {
  110. kAsyncThreadStackSize = 2048UL,
  111. kSleepAsync = 90UL,
  112. kSleepThreading = 0UL,
  113. kStdSectorSize = 512,
  114. kTagBytesxSector = 12
  115. };
  116.  
  117. #define    kMyZFMacPlus    5
  118. #define    kDragMFMacPlus    5
  119.  
  120. #define    gestaltBgndMouseDownSupport    10
  121.  
  122. typedef struct {
  123.     FSSpec    destFile;
  124.     ScriptCode    theScript;
  125.     } StdFileResult, *StdFileResultPtr;
  126.  
  127. /* dialog box manager */
  128.  
  129. struct dialogitems {
  130.     short    itemNumber;
  131.     short    group;
  132.     long    refCon;
  133.     };
  134.  
  135. typedef struct dialogitems dialogItems, *dialogItemsPtr;
  136.  
  137. struct wakeupCntrlParam {
  138.     Ptr        bufferLimit;
  139.     ProcessSerialNumber    mypsn;
  140.     CntrlParam        pb;
  141.     };
  142.  
  143. typedef struct wakeupCntrlParam wakeupCntrlParam, *wakeupCntrlParamPtr;
  144.  
  145. struct wakeupIOParam {
  146.     Ptr        bufferLimit;
  147.     ProcessSerialNumber    mypsn;
  148.     IOParam        pb;
  149.     };
  150.  
  151. typedef struct wakeupIOParam wakeupIOParam, *wakeupIOParamPtr;
  152.  
  153. struct wakeupHVolumeParam {
  154.     Ptr        bufferLimit;
  155.     ProcessSerialNumber    mypsn;
  156.     HVolumeParam        pb;
  157.     };
  158.  
  159. typedef struct wakeupHVolumeParam wakeupHVolumeParam, *wakeupHVolumeParamPtr;
  160.  
  161. struct wakeupHParamBlockRec {
  162.     Ptr        bufferLimit;
  163.     ProcessSerialNumber    mypsn;
  164.     HParamBlockRec        pb;
  165.     };
  166.  
  167. typedef struct wakeupHParamBlockRec wakeupHParamBlockRec, *wakeupHParamBlockPtr;
  168.  
  169. struct ZoomFactorRec {
  170.     short        myFactor;
  171.     short        DragMFactor;
  172.     };
  173.  
  174. typedef struct ZoomFactorRec ZoomFactorRec;
  175.  
  176. //=============================================================================
  177.  
  178. #if PRAGMA_IMPORT_SUPPORTED
  179. #pragma import on
  180. #endif
  181.  
  182. typedef pascal OSErr (*BkgClickHandlerProcPtr)(const EventRecord *event, SInt16 *action);
  183.  
  184. #if GENERATINGCFM
  185. typedef UniversalProcPtr BkgClickHandlerUPP;
  186. #else
  187. typedef BkgClickHandlerProcPtr BkgClickHandlerUPP;
  188. #endif
  189.  
  190. enum {
  191.     uppBkgClickHandlerProcInfo = kPascalStackBased
  192.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  193.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(EventRecord *)))
  194.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(SInt16 *)))
  195. };
  196.  
  197. #if GENERATINGCFM
  198. #define NewBkgClickHandlerProc(userRoutine)        \
  199.         (BkgClickHandlerUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppBkgClickHandlerProcInfo, GetCurrentArchitecture())
  200. #else
  201. #define NewBkgClickHandlerProc(userRoutine)        \
  202.         ((BkgClickHandlerUPP) (userRoutine))
  203. #endif
  204. /*
  205. #if GENERATINGCFM
  206. #define CallSelectorFunctionProc(userRoutine, selector, response)        \
  207.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppBkgClickHandlerProcInfo, (selector), (response))
  208. #else
  209. #define CallSelectorFunctionProc(userRoutine, selector, response)        \
  210.         (*(userRoutine))((selector), (response))
  211. #endif
  212. */
  213. extern pascal OSErr InstallBackgroundClickHandler(BkgClickHandlerUPP bkgHandler)
  214.  THREEWORDINLINE(0x3F3C, 0x0055, 0xA88F);
  215.  
  216. #if PRAGMA_IMPORT_SUPPORTED
  217. #pragma import off
  218. #endif
  219.  
  220. #pragma internal on
  221.  
  222. /* WantThisHandleSafe locks high the handle and returns the previous state */
  223.  
  224. #if GENERATING68K
  225. #pragma parameter __D0 WantThisHandleSafe(__A0)
  226. extern pascal SignedByte WantThisHandleSafe(Handle myH) = {0xA069, 0x1F00, 0xA064, 0xA029, 0x101F};
  227. #else
  228. SignedByte WantThisHandleSafe(Handle myH);
  229. #endif
  230.  
  231. #if GENERATING68K
  232. #pragma parameter __D0 AMultBDivC(__D0,__D1,__D2)
  233. extern pascal SInt16 AMultBDivC(SInt16 a, SInt16 b, SInt16 c) = {0xC1C1, 0x81C2};
  234. #else
  235. int AMultBDivC(int a, int b, int c);
  236. #endif
  237.  
  238. #if GENERATING68K
  239. #pragma parameter MyZeroBuffer(__A0,__D1)
  240. extern pascal void MyZeroBuffer(long *p, long s) = {0x7000, 0x20C0, 0x51C9, 0xFFFC };
  241.  
  242. #pragma parameter MyFillBuffer(__A0,__D1,__D0)
  243. extern pascal void MyFillBuffer(long *p, long s, long filler) = {0x20C0, 0x51C9, 0xFFFC };
  244.  
  245. #pragma parameter __D0 mySwap(__D0)
  246. extern pascal long mySwap(long s) = {0x4840 };
  247. #else
  248. void MyZeroBuffer(long *p, long s);
  249. void MyFillBuffer(long *p, long s, long filler);
  250. long mySwap(long s);
  251. #endif
  252.  
  253. void ZoomingRects(ZoomFactorRec * const zfr, const Rect * const firstRect, const Rect * const lastRect, ZoomAcceleration acc);
  254. OSErr AddSTRRes2Doc(const FSSpecPtr theDoc, OSType myFcrea, OSType myFtype, short STRid, ScriptCode lScript);
  255. OSErr AddSTRHand2Doc(const FSSpecPtr theDoc, OSType myFcrea, OSType myFtype, StringHandle msgString, ScriptCode lScript);
  256. OSErr AddRes2Doc(const FSSpecPtr theDoc, Handle thisHandle, ResType rType, short rID);
  257. OSErr AddRes2DocOpen(Handle thisHandle, ResType rType, short rID);
  258. void SendmyAE(AEEventClass, AEEventID myAEvtID, AEIdleProcPtr, AESendMode theMode);
  259. void SendmyAEPShort(AEEventClass myclass, AEEventID myAEvtID, AEIdleProcPtr IdleFunct, AESendMode theMode, short theAlert);
  260. OSErr SendRevealToFinder(Handle fld, AEIdleProcPtr IdleFunct,
  261.                         void (*failProc)(void));
  262. Handle NewHandleGeneral(UInt32 blockSize);
  263. Handle Get1ResGeneral(ResType theType, short theID);
  264. OSType FindFinderAtEaseProcess(ProcessSerialNumber * const);
  265. OSType FindFinderProcess(void);
  266. OSErr SendShutdownToFinder(AEIdleProcPtr, Boolean);
  267. short StopAlert_UPP(short alertID, ModalFilterProcPtr filterProc);
  268. short StopAlert_AE(short alertID, ModalFilterProcPtr filterProc, AEIdleProcPtr IdleFunct);
  269. short CautionAlert_UPP(short alertID, ModalFilterProcPtr filterProc);
  270. short CautionAlert_AE(short alertID, ModalFilterProcPtr filterProc, AEIdleProcPtr IdleFunct);
  271. short NoteAlert_UPP(short alertID, ModalFilterProcPtr filterProc);
  272. short NoteAlert_AE(short alertID, ModalFilterProcPtr filterProc, AEIdleProcPtr IdleFunct);
  273. short Alert_UPP(short alertID, ModalFilterProcPtr filterProc);
  274. short Alert_AE(short alertID, ModalFilterProcPtr filterProc, AEIdleProcPtr IdleFunct);
  275.  
  276.  
  277. short HandleDialog(ModalFilterProcPtr filterProc,
  278.                     dialogItemsPtr things,
  279.                     void (*initProc)(DialogRef),
  280.                     void (*userProc)(DialogRef, Handle, short),
  281.                     short resId);
  282.  
  283. /* about box manager */
  284.  
  285. void myAbout(void (*theIdleProc)(void),
  286.             UserItemUPP DrawQTPict,
  287.             void (*UpdateProc)(EventRecord *),
  288.             void (*ActivateProc)(EventRecord *)
  289.             );
  290. Handle OpenSplash(DialogRef * const, UserItemUPP DrawQTPict);
  291. void DisposeSplash(Handle, DialogRef);
  292. void myMovableModalAbout(
  293.             Point *aboutTopLeft,
  294.             Point *creditsTopLeft,
  295.             void (*AdjustMenus)(TEHandle),
  296.             void (*Handle_My_Menu)(long),
  297.             void (*DomyKeyEvent)(EventRecord *),
  298.             void (*DoUpdate)(EventRecord *),
  299.             void (*DoActivate)(EventRecord *),
  300.             void (*DoHiLevEvent)(EventRecord *),
  301.             void (*DoOSEvent)(EventRecord *),
  302.             void (*DoIdle)(void),
  303.             unsigned long minSleep
  304.             );
  305.  
  306. void CopyEMailAddrToClip(void);
  307. void CopyWWWURLToClip(short);
  308. Boolean GetFontNumber(ConstStr255Param fontName, short * const fontNum);
  309. Boolean CmdPeriodOrEsc(const EventRecord * const theEvent);
  310. Boolean CmdPeriodOrEscConfirm(const EventRecord * const theEvent, short alertID, ModalFilterProcPtr filterProc);
  311. void HandleRegistration(/*ModalFilterProcPtr filterProc,*/
  312.                         Point *regDTopLeft,
  313.                         long (*regCfgInfo)(Handle, long, StringPtr),
  314.                         void (*AdjustMenus)(TEHandle),
  315.                         void (*Handle_My_Menu)(long),
  316.                         void (*DomyKeyEvent)(EventRecord *),
  317.                         void (*DoUpdate)(EventRecord *),
  318.                         void (*DoActivate)(EventRecord *),
  319.                         void (*DoHiLevEvent)(EventRecord *),
  320.                         void (*DoOSEvent)(EventRecord *),
  321.                         void (*DoIdle)(void),
  322.                         UInt32 minSleep,
  323.                         UInt16 dollars);
  324. void CopyBugReportForm(long (*regCfgInfo)(Handle, long, StringPtr));
  325. OSErr AskForDestFile(StdFileResultPtr whichFile, ConstStr255Param prompt, StringPtr docName);
  326. void BCDVersNumToString(long num, StringPtr str);
  327. void BCDLongVersNumToString(long num, StringPtr str);
  328. Boolean TrapAvailable(short theTrap);
  329. OSErr InstallRequiredAEHandlers(AEEventHandlerProcPtr myOAPP,
  330.                                 AEEventHandlerProcPtr myODOC,
  331.                                 AEEventHandlerProcPtr myPDOC,
  332.                                 AEEventHandlerProcPtr myQUIT);
  333. void FileCreationError(OSErr err);
  334.  
  335. #pragma internal reset
  336.  
  337. //====================================================================
  338.  
  339. //#if GENERATING68K
  340. //#pragma parameter MyNumToString(__D0,__A0)
  341. //extern pascal void MyNumToString(long theNum,Str255 theString)
  342. // TWOWORDINLINE(0x4267, 0xA9EE);
  343. //#else
  344. #define    MyNumToString    NumToString
  345. //#endif
  346.  
  347. /*
  348. #ifdef    FABERDEBUG
  349. #define    SAFEDESTROY(disposFn, type, obj, realtype)    {disposFn((type)obj); obj = (realtype)0xDEADBEEF;}
  350. #else
  351. */
  352. #define    SAFEDESTROY(disposFn, type, obj, realtype)    {disposFn((type)obj); obj = nil;}
  353. //#endif
  354.  
  355. #define    SSAFEDESTROY(disposFn, type, obj, realtype)    if (obj) SAFEDESTROY(disposFn, type, obj, realtype)
  356.  
  357.  
  358. #define numOfLongs(s)    ((((UInt32)s)>>2) - 1L)
  359.  
  360. #define toMenu(m, i)    (((long)m << 16) + i)
  361. #define    CHARFROMMESSAGE(mess)    (*(((unsigned char *)(&(mess))) + 3))
  362. #define ISAPPWINDOW(w)    (((WindowPeek) w)->windowKind >= userKind)
  363. #define ISDLGWINDOW(w)    (((WindowPeek) w)->windowKind == dialogKind)
  364. #define ISDAWINDOW(w)    (((WindowPeek) w)->windowKind < 0)
  365. #define isMovableModal(w)    (GetWVariant(w) == movableDBoxProc)
  366.  
  367. #define MAX(a, b)    ((a) > (b) ? (a) : (b))
  368. #define MIN(a, b)    ((a) < (b) ? (a) : (b))
  369.  
  370. /* Define HiWrd and LoWrd macros for efficiency. */
  371. #define HiWrd(aLong)    (short)(((UInt32)aLong) >> 16)
  372. #define LoWrd(aLong)    (short)((aLong) & 0xFFFF)
  373.  
  374. #define PRCT_T(f)    (f->portRect.top)
  375. #define PRCT_L(f)    (f->portRect.left)
  376. #define PRCT_B(f)    (f->portRect.bottom)
  377. #define PRCT_R(f)    (f->portRect.right)
  378.  
  379. #define rheight(r)    ((r).bottom - (r).top)
  380. #define rwidth(r)    ((r).right - (r).left)
  381.  
  382. #endif
  383.